// stores/userStore.ts
import { defineStore } from 'pinia'
import { ref } from 'vue'

interface UserResp {
  createdAt: Date
  no: string
  username: string
  avatar: string
  email: string
}

export const useUserStore = defineStore('user', () => {
  // 状态
  const user = ref<UserResp | null>(null)
  
  // actions
  const setUser = (userData: UserResp) => {
    user.value = userData
  }
  
  const clearUser = () => {
    user.value = null
  }
  
  // getters
  const getUserNo = () => user.value?.no || ''
  const getUsername = () => user.value?.username || ''
  const getAvatar = () => user.value?.avatar || ''
  const getEmail = () => user.value?.email || ''

  return {
    user,
    setUser,
    clearUser,
    getUserNo,
    getUsername,
    getAvatar,
    getEmail
  }
})